import axios from 'axios'

export function FeaturedList(sku) {
  return axios.get('/api/Products/'+ sku, {
  }).then((response) => {
    return Promise.resolve(response.data)

  })
    .catch(function (error) {
      console.log(error)
    })
}

export function getCategories(id) {
  const url = '/api/Categories/' + id
  return axios.get(url)
    .then((response) => {
      return Promise.resolve(response.data)
    })
    .catch(error => {
      console.log(error)
    })
}

export function getFeaturedDetail(sku) {
  const url = '/api/Products/' + sku
  return axios.get(url)
    .then(res => {
      return Promise.resolve(res.data)
    })
    .catch(err => {
      console.log(err)
      return Promise.reject(err)
    })
}

// 查询产品的浏览量
export function getProductView(sku) {
  const url = `/api/ProductView/${sku}`
  return axios.get(url)
    .then(response => {
      return Promise.resolve(response.data)
    })
    .catch(error => {
      console.log(error)
    })
}

// 浏览量+1
export function postProductView(sku) {
  const url = `/api/ProductView/${sku}`
  return axios.post(url)
    .then(response => {
      return Promise.resolve(response.data)
    })
    .catch(error => {
      console.log(error)
    })
}
